//
//  SEGUserFeedbackManager.m
//  SEGUhomeStandard
//
//  Created by 刘山 on 2018/3/29.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGUserFeedbackManager.h"

@implementation SEGUserFeedbackManager
/**
 *  请求用户反馈详情
 */
+ (void)requestFeedbackDetailWithSugId:(NSString*)sugId Finished:(SEGNetworkRequestCallBack)finished
{
    NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:sugId, @"sugId", nil];
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/rest-api/v1/couster-suggest/detail.json",nil];

    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        NSDictionary* data = [result objectForKey:@"data"];
        NSMutableDictionary* notifyDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:errorMessage, @"message", codeType, @"code", nil];
        
        if(!isSuccessed){
            finished(notifyDic, nil);
            return;
        }
        
        if (![data isKindOfClass:[NSDictionary class]]) {
            finished(notifyDic, nil);
            return;
        }
        
        NSArray* cousterSuggestReplys = [data objectForKey:@"cousterSuggestReplys"];
        NSMutableArray* objectArray = [NSMutableArray array];
        for (NSDictionary* dic in cousterSuggestReplys) {
            NSMutableDictionary* retDic = [NSMutableDictionary dictionary];
            if ([dic objectForKey:@"reId"]) {
                [retDic setObject:[dic objectForKey:@"reId"] forKey:@"reId"];
            }
            
            if ([dic objectForKey:@"sugId"]) {
                [retDic setObject:[dic objectForKey:@"sugId"] forKey:@"sugId"];
            }
            if ([dic objectForKey:@"context"]) {
                [retDic setObject:[dic objectForKey:@"context"] forKey:@"context"];
            }
            if ([dic objectForKey:@"sugType"]) {
                [retDic setObject:[dic objectForKey:@"sugType"] forKey:@"sugType"];
            }
            if ([dic objectForKey:@"userId"]) {
                [retDic setObject:[dic objectForKey:@"userId"] forKey:@"userId"];
            }
            
            if ([dic objectForKey:@"userName"]) {
                [retDic setObject:[dic objectForKey:@"userName"] forKey:@"userName"];
            }
            if ([dic objectForKey:@"userType"]) {
                [retDic setObject:[dic objectForKey:@"userType"] forKey:@"userType"];
            }
            
            if ([dic objectForKey:@"createDate"]) {
                [retDic setObject:[dic objectForKey:@"createDate"] forKey:@"createDate"];
            }
            
            if ([dic objectForKey:@"updateDate"]) {
                [retDic setObject:[dic objectForKey:@"updateDate"] forKey:@"updateDate"];
            }
            
            [objectArray addObject:retDic];
        }
        
        [notifyDic setObject:objectArray forKey:@"ObjectArray"];
        
        if ([data objectForKey:@"context"]) {
            [notifyDic setObject:[data objectForKey:@"context"] forKey:@"context"];
        }
        if ([data objectForKey:@"createDate"]) {
            [notifyDic setObject:[data objectForKey:@"createDate"] forKey:@"createDate"];
        }
        
        finished(notifyDic, nil);
        
    }];
}

/**
 *  请求发送用户反馈会话
 */
+ (void)requestSendReplyWithContext:(NSString*)context SugId:(NSString*)sugId Finished:(SEGNetworkRequestCallBack)finished
{
    NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:context, @"context", sugId, @"sugId", nil];
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/rest-api/v1/couster-suggest/replay.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(result, nil);
    }];
}

/**
 *  请求用户反馈
 */
+ (void)requestFeedbackList:(SEGNetworkRequestCallBack)finished
{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/rest-api/v1/couster-suggest/list.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:nil finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(result, nil);
    }];
}

@end
